# This file is part of GPropertyGrid project. 
# The COPYRIGHT file at the top level of this repository 
# contains the full copyright notices and license terms.

from gi.repository import Gtk
from . propertygridproperty import PropertyGridProperty

class PropertyCheck(PropertyGridProperty):
    def __init__(self, name, id=None, default=None, description=None, force_value=False):
        self._check = Gtk.CheckButton()
        self._check.connect("toggled", self.on_toggled)
        
        super(PropertyCheck, self).__init__(name=name, value_widget=self._check,
                            id=id,
                            default=default, 
                            description=description, 
                            force_value=force_value)
                            
        self.set_text(default)        
        if default==True:
            self._check.set_active(True)

    def on_toggled(self, wg):
        self.on_change()
        
    def set_text(self, value):
        if value==None:
            self.set_value_text(None)
        else:
            if value==True:
                self.set_value_text("True")
            else:
                self.set_value_text("False")
                
#    def on_enter(self):
#        pass       

    def on_leave(self):
        pass

    def on_change(self):
        if not super(PropertyCheck, self).on_change():
            return False
        self.value=self._check.get_active()
        self.set_text(self.value)
        self.has_changed=True
        return True
    
